<?php if(isset($isInsert) && $isInsert){
?>
<script>
	ajax('listContent','<?php echo $this->params['controller']?>/lists');
	closeBox('addContent','mainContent');
</script>
<?php
}
else{
?>
<script type="text/javascript">
function addImage(imageId,filename){	
	$('#'+imageId).find('.galleryImageContainer').mouseenter(function(){			
		var imgItem=$('#'+this.parentNode.id).find('.imageItem');			
		imgItem.fadeIn(100)
	}).mouseleave(function(){
		var imgItem=$('#'+this.parentNode.id).find('.imageItem');
		imgItem.fadeOut(100)
	});

	newImg=document.createElement("img");	

	$('#'+imageId).find('.galleryImageContainer').children().first().before(newImg);
	newImg.onload = function () {
		var width=245;
		var height=200;
		var newSize = new resizeImage(this.width,this.height,width,height);
		this.width=newSize.width;
		this.height=newSize.height;
		this.style.marginLeft=(width-this.width)/2+"px";
		this.style.marginTop=(height-this.height)/2+"px";
		this.style.position="absolute";
	};
	newImg.src =SITE_URL+'/uploaded/ProductImage/thumb/'+filename;	
}
</script>
<fieldset>
    <legend><?php echo $this->data[$uses[0]]['name'].' '._resource('gallery',true);?>
    	<?php if($webConfig['is_multi_lang']){?>
       		<img class="Tips1" title="<?php echo $listLang[$locale]?>" border="0" src="<?php echo $this->webroot.'img/backend/flag/'.$locale.'.png'?>">
       		<?php }?>
    </legend>
<center><div id="message">&nbsp;</div></center>
<?php if($this->Session->read('message')){
	echo '<script>showMessage("addContent","'.$this->Session->read('message').'");</script>';
	$this->Session->delete('message');	
	}?>
<?php if($this->Session->read('error')){
	echo '<script>showMessage("addContent","'.$this->Session->read('error').'",1);</script>';
	$this->Session->delete('error');
}?>
    <form id="adminForm" name="adminForm" method="post" action="<?php echo $this->params['controller']?>/gallery/<?php echo $this->data[$uses[0]]['id'].'/'.$locale ?>"  onsubmit="onFormSubmit();return false;">
    <?php
		echo $this->Form->hidden('ProductImage.image_category_id',array('value'=>$this->data[$uses[0]]['id']));		

				

	?>
	    
	<div style="width: 80px; height: 18px; border: solid 1px #7FAAFF; background-color: #C5D9FF; padding: 2px;float: right;">
		<span id="spanButtonPlaceholder"></span>
	</div>
	<div style="clear:both;height:20px;"></div>
	<div id="divUploadContainer">
		<?php if(count($imgdata)>0){
			foreach($imgdata as $k=>$v){
			?>
       		<div class="progressWrapper" id="imageUploaded_<?php echo $v['ProductImage']['id']?>" style="float: left; opacity: 1;">
	       		<div class="galleryImageContainer" style="width: 245px; height: 200px;">		       		
		       		<div class="imageItem" style="width: 235px; padding-right: 10px; display: none;">
		       			<a title="remove" onclick="removeImage('imageUploaded_<?php echo $v['ProductImage']['id']?>','<?php echo $v['ProductImage']['image']?>')" href="javascript:;">&nbsp;&nbsp;X&nbsp;&nbsp;</a>
		       		</div>
	       		</div>
	       		<input type="hidden" class="inputHidden" name="data[ProductImage][image][imageUploaded_<?php echo $v['ProductImage']['id']?>]" value="<?php echo $v['ProductImage']['image']?>">
	       		<input style="margin-top: 5px; margin-bottom: 45px; width: 250px;" name="data[ProductImage][title][<?php echo $v['ProductImage']['image']?>]" value="<?php echo $v['ProductImage']['title']?>">
       		</div>
       		<script type="text/javascript">
       			addImage('imageUploaded_<?php echo $v['ProductImage']['id']?>','<?php echo $v['ProductImage']['image']?>');
       		</script>
       	<?php }}?>
    </div>
       		
	
	<div style="clear:both"></div>
	<center>
    <div style="width:130px">
          <div class="button"><a onclick="onFormSubmit()" href="javascript:;" title="<?php echo _resource('save') ?>"  > <span class="icon-32-save"> </span></a> </div>          
          <div class="button"><a onclick="closeBox('addContent','mainContent')" href="javascript:;" title="<?php echo _resource('close') ?>"  > <span class="icon-32-cancel"> </span></a> </div>
    </div>
    </center>
      </form>
</fieldset>


<script>	
function onFormSubmit(){
	deactivateEditors();
	submitForm('adminForm','addContent');	
}

function removeImage(imageId,filename){
	ajaxNoRespond("images/remove/"+filename);
	$('#'+imageId).remove();	
}	



	//for swfupload plugin
	$(document).ready(function () {

		swfu = new SWFUpload({
			// Backend Settings
			upload_url: "<?php echo BACKEND_URL.'fileuploads/imageupload/image/ProductImage/'.$this->data[$uses[0]]['id']?>",
			post_params: {"PHPSESSID": "<?php echo session_id(); ?>"},

			// File Upload Settings
			file_size_limit : "10 MB",
			file_types : "*.jpg;*.png;*.gif",
			file_types_description : "JPG Images",
			file_upload_limit : 0,

			// Event Handler Settings - these functions as defined in Handlers.js
			//  The handlers are not part of SWFUpload but are part of my website and control how
			//  my website reacts to the SWFUpload events.
			swfupload_preload_handler : preLoad,
			swfupload_load_failed_handler : loadFailed,
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
			upload_complete_handler : uploadComplete,

			// Button Settings
			button_image_url : "<?php echo $this->webroot?>plugins/SWFUpload/images/SmallSpyGlassWithTransperancy_17x18.png",
			button_placeholder_id : "spanButtonPlaceholder",
			button_width: 80,
			button_height: 18,
			button_text : '<span class="button"><?php _resource('add photo') ?><br /></span>',
			button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
			button_text_top_padding: 0,
			button_text_left_padding: 18,
			button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
			button_cursor: SWFUpload.CURSOR.HAND,
			
			// Flash Settings
			flash_url : "<?php echo $this->webroot?>plugins/SWFUpload/js/swfupload.swf",
			flash9_url : "<?php echo $this->webroot?>plugins/SWFUpload/js/swfupload_fp9.swf",

			custom_settings : {					
				//upload_target : "divFileProgressContainer",//upload status
				type:2,//1: image, 2: gallery 
				uploadContainer:"divUploadContainer",// contain upload , use for multi upload				
				fieldName: "<?php echo 'data[ProductImage][image]'?>",
				fieldTitle: "<?php echo 'data[ProductImage][title]'?>",
				//uploadType: "image-gallery", //upload type: image, doc
				numOfMaxUpload:0 //max of upload file, 1 for single, >1 for multi, 0 for unlimit
			},
			
			// Debug Settings
			debug: false
		});
	});
	scrollTopTo('addContent');		
</script>
<?php } ?>
